
<!DOCTYPE HTML>
<html lang="zh-cn" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>跨域与代理 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="Best-practice.html" />
    
    
    <link rel="prev" href="Configuration.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="輸入並搜尋" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    总览
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../Getting-started.html">
            
                <a href="../Getting-started.html">
            
                    
                    开始
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../Features.html">
            
                <a href="../Features.html">
            
                    
                    技术栈
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../Structure.html">
            
                <a href="../Structure.html">
            
                    
                    目录结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="./">
            
                <a href="./">
            
                    
                    深入了解
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="State-management.html">
            
                <a href="State-management.html">
            
                    
                    谈状态管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="URL-is-soul-of-SPA.html">
            
                <a href="URL-is-soul-of-SPA.html">
            
                    
                    URL 是单页应用的精华
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="Service-layer.html">
            
                <a href="Service-layer.html">
            
                    
                    引入服务层
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="Ajax-interface.html">
            
                <a href="Ajax-interface.html">
            
                    
                    Ajax 接口化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="Configuration.html">
            
                <a href="Configuration.html">
            
                    
                    配置
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.5.6" data-path="CORS-and-Proxy.html">
            
                <a href="CORS-and-Proxy.html">
            
                    
                    跨域与代理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="Best-practice.html">
            
                <a href="Best-practice.html">
            
                    
                    最佳实践
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../Reference.html">
            
                <a href="../Reference.html">
            
                    
                    参考
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" >
            
                <a target="_blank" href="https://github.com/kenberkeley/vue-demo/issues">
            
                    
                    问题反馈（issues）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" >
            
                <a target="_blank" href="https://github.com/kenberkeley/vue-demo/releases">
            
                    
                    版本迭代（releases）
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本書使用 GitBook 釋出
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >跨域与代理</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#xA7;-&#x8DE8;&#x57DF;&#x4E0E;&#x4EE3;&#x7406;">&#xA7; &#x8DE8;&#x57DF;&#x4E0E;&#x4EE3;&#x7406;</h1>
<p>&#x76EE;&#x524D;&#x4E3B;&#x8981;&#x662F;&#x4E24;&#x79CD;&#x65B9;&#x6848;&#xFF1A;&#x76F4;&#x63A5;&#x8DE8;&#x57DF;&#x4E0E;&#x4EE3;&#x7406;&#x8F6C;&#x53D1;</p>
<h3 id="&#x2299;-&#x76F4;&#x63A5;&#x8DE8;&#x57DF;&#xFF08;&#x4E0D;&#x63A8;&#x8350;&#xFF09;">&#x2299; &#x76F4;&#x63A5;&#x8DE8;&#x57DF;&#xFF08;&#x4E0D;&#x63A8;&#x8350;&#xFF09;</h3>
<pre><code>xhr &#x63A5;&#x53E3;  &lt;--&#xFF08;&#x76F4;&#x63A5;&#x8DE8;&#x57DF;&#xFF09;--&gt; API &#x670D;&#x52A1;&#x5668;
</code></pre><blockquote>
<p>&#x5F00;&#x53D1;&#x8FC7;&#x7A0B;&#x4E2D;&#xFF0C;Chrome &#x53EF;&#x4EE5;&#x4F7F;&#x7528; <a href="https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi" target="_blank">Allow-Control-Allow-Origin: *</a> &#x63D2;&#x4EF6;&#x89E3;&#x9664;&#x540C;&#x6E90;&#x7B56;&#x7565;&#x7684;&#x9650;&#x5236;</p>
</blockquote>
<h3 id="&#x2299;-&#x4EE3;&#x7406;&#x8F6C;&#x53D1;&#xFF08;&#x63A8;&#x8350;&#xFF09;">&#x2299; &#x4EE3;&#x7406;&#x8F6C;&#x53D1;&#xFF08;&#x63A8;&#x8350;&#xFF09;</h3>
<pre><code>xhr &#x63A5;&#x53E3; &lt;--&#xFF08;&#x5F00;&#x53D1;&#x670D;&#x52A1;&#x5668;&#x4EE3;&#x7406;&#x8F6C;&#x53D1;&#xFF09;--&gt; API &#x670D;&#x52A1;&#x5668;
</code></pre><blockquote>
<p>&#x5B9E;&#x9645;&#x4E0A; <code>xhr &#x63A5;&#x53E3;</code> &#x4E0E; <code>&#x5F00;&#x53D1;&#x670D;&#x52A1;&#x5668;</code> &#x4E2D;&#x95F4;&#x8FD8;&#x6709;&#x4E00;&#x5C42; <a href="https://browsersync.io/" target="_blank"><code>BrowserSync</code></a> &#x4EE3;&#x7406;&#xFF08;&#x7528;&#x4E8E;&#x591A;&#x7AEF;&#x8054;&#x5408;&#x540C;&#x6B65;&#x8C03;&#x8BD5;&#xFF09;&#xFF0C;&#x4F46;&#x4E0E;&#x672C;&#x7BC7;&#x8BA8;&#x8BBA;&#x7684;&#x8DE8;&#x57DF;&#x4EE3;&#x7406;&#x65E0;&#x5173;</p>
</blockquote>
<hr>
<h4 id="&#x76F8;&#x5173;&#x914D;&#x7F6E;">&#x76F8;&#x5173;&#x914D;&#x7F6E;</h4>
<ul>
<li><code>xhr &#x63A5;&#x53E3;</code>&#xFF1A;&#x89C1; <code>src/services/xhr/</code>  </li>
<li><code>&#x5F00;&#x53D1;&#x670D;&#x52A1;&#x5668;&#x4EE3;&#x7406;&#x8F6C;&#x53D1;</code>&#xFF1A;&#x89C1; <code>build/dev.js</code> &#x4E2D;&#x4F7F;&#x7528; <a href="https://github.com/chimurai/http-proxy-middleware" target="_blank"><code>http-proxy-middleware</code></a> &#x5B9E;&#x73B0;</li>
<li><code>BrowserSync</code>&#xFF1A;&#x89C1; <code>build/webpack.dev.conf.js</code> &#x4E2D;&#x7684; <a href="https://github.com/Va1/browser-sync-webpack-plugin" target="_blank"><code>BrowserSyncPlugin</code></a> &#x914D;&#x7F6E;</li>
<li>&#x4E0A;&#x8FF0;&#x5404;&#x9879;&#x670D;&#x52A1;&#x7684;&#x7AEF;&#x53E3;&#x914D;&#x7F6E;&#xFF1A;<code>build/config/PORTS.js</code></li>
</ul>
<h4 id="&#x751F;&#x4EA7;&#x73AF;&#x5883;&#x4E0B;&#x7684;&#x4EE3;&#x7406;">&#x751F;&#x4EA7;&#x73AF;&#x5883;&#x4E0B;&#x7684;&#x4EE3;&#x7406;</h4>
<p>&#x4E00;&#x822C;&#x662F;&#x4F7F;&#x7528; Nginx &#x90E8;&#x7F72; <code>dist/</code>&#xFF0C;&#x914D;&#x7F6E; <code>proxy_pass</code> &#x5230;&#x5BF9;&#x5E94;&#x7684;&#x540E;&#x7AEF;&#x670D;&#x52A1;&#xFF08;&#x8BE6;&#x60C5;&#x8BF7;&#x81EA;&#x884C;&#x67E5;&#x9605;&#x76F8;&#x5173;&#x8D44;&#x6599;&#xFF09;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="Configuration.html" class="navigation navigation-prev " aria-label="Previous page: 配置">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="Best-practice.html" class="navigation navigation-next " aria-label="Next page: 最佳实践">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"跨域与代理","level":"1.5.6","depth":2,"next":{"title":"最佳实践","level":"1.5.7","depth":2,"path":"development/Best-practice.md","ref":"development/Best-practice.md","articles":[]},"previous":{"title":"配置","level":"1.5.5","depth":2,"path":"development/Configuration.md","ref":"development/Configuration.md","articles":[]},"dir":"ltr"},"config":{"plugins":[],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"language":"zh-cn","gitbook":"*"},"file":{"path":"development/CORS-and-Proxy.md","mtime":"2016-12-28T14:26:53.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-04-22T13:44:37.529Z"},"basePath":"..","book":{"language":"zh-cn"}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

